//城市选择
var app = getApp();
Page({
  data: {
    popErrorMsg: ""
  },

  submitApply: function (e) {
    var formValue = e.detail.value;
    var userName = formValue.userName;
    var phone = formValue.phone;
    var sellerName = formValue.sellerName;
    setTimeout(() => {
      if (userName == '' || userName == null) {
        this.setData(
          { popErrorMsg: "真实姓名不能为空" }
        );
        this.ohShitfadeOut();
        return;
      } else if (phone == '' || phone == null){
        this.setData(
          { popErrorMsg: "联系电话不能为空" }
        );
        this.ohShitfadeOut();
        return;
      } else if (sellerName == '' || sellerName == null) {
        this.setData(
          { popErrorMsg: "店铺名称不能为空" }
        );
        this.ohShitfadeOut();
        return;
      }else {
        this.apply(userName,phone,sellerName);
      }
    }, 10)
  },

  apply(userName, phone, sellerName){
    app.request("UserApplyManagerService", "addUserTask",
      {
        userId: app.d.userId,
        taskType: 0,
        phone: phone,
        userName: userName,
        sellerName: sellerName
      }, function (data) {
        wx.switchTab({
          url: '../user/user'
        })
        wx.showToast({
          title: '提交成功',
          duration: 2000
        });
      });
  },

  ohShitfadeOut: function() {
    var fadeOutTimeout = setTimeout(() => {
      this.setData({ popErrorMsg: '' });
      clearTimeout(fadeOutTimeout);
    }, 3000);
  },

  onLoad: function (options) {
    // 生命周期函数--监听页面加载
    var that = this;
    wx.setNavigationBarTitle({ title: '成为分销商' })
    that.setData({
      cartId: options.cartId
    })
  },
})